home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
demos
/
GL
/
libdemo
/
options.h
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
4KB
|
152 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
#ifndef __options__
#define __options__
#include <stdlib.h>
extern char * appName;
class option
{
public:
// API:
// The constructor declares the option letter and a short description.
// wasGiven returns true if the option was given on the command line.
//
option(int, char *);
int wasGiven();
// internals:
virtual int checkOption(int, char *); // Called from processOptions
// class, this performs the
// comparison.
static option * head; // List of all command line
option * next; // options.
void usage(); // Called when the usage line
// should be printed.
protected:
int opt;
char * description;
int given;
static char optString[256]; // Store option chars here for
// use in getopt.
};
class stringOption : public option
{
public:
// API:
// Constructor is same as option except and extra optional default.
// getArgument() returns the option argument given.
//
stringOption(int, char *, char * = 0);
char * getArgument();
protected:
char * arg;
virtual int checkOption(int, char *); // See if this option
// corresponds to the given
// option. If so, save the
// argument.
};
class manyArgsOption : public stringOption
{
public:
// Constructor expects option char, description, default string, and
// number of comma separated arguments expected in argument.
// getNumber() gets the number of args gotten.
// getArg(n) gets option argument # n.
//
manyArgsOption(int, char *, char *, int);
int getNumber();
char * getArg(int n);
private:
void parse(); // Do the actuall parsing of
// the arguments.
char ** args;
int expected;
int received;
};
class floatOption : public manyArgsOption
{
public:
// Constructor expects option char, description, default string, and
// number of comma separated floats expected in argument.
// getFloat(n) gets float option argument # n.
//
floatOption(int opt, char * desc, char * def, int num)
: manyArgsOption(opt, desc, def, num) {}
float getFloat(int n) { return atof(getArg(n)); }
};
class intOption : public manyArgsOption
{
public:
// Constructor expects option char, description, default string, and
// number of comma separated ints expected in argument.
// getInt(n) gets int option argument # n
//
intOption(int opt, char * desc, char * def, int num)
: manyArgsOption(opt, desc, def, num) {}
int getInt(int n) { return atoi(getArg(n)); }
};
class commandArgument
{
public:
// Constructor expects a description and the maximum number of arguments.
// getNumber() gets the number of args gotten.
// getArg(n) gets option argument # n.
//
commandArgument(char *, int);
int getNumber();
char * getArg(int n);
// internal
int setArgument(int, char **); // Called from processOptions.
// Returns 0 on error.
void usage(); // Prints usage line for argument.
char * description;
private:
char ** args;
int expected;
int received;
};
// User defines this function. The number of command line arguments and and
// array of pointers to the arguments are passed. At this point the options
// are already removed.
//
extern void Main();
#endif